/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.yournamehere.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.*;
/**
 *
 * @author D4v1D
 */
public class LoaderPanel extends VerticalPanel{
        private SudokuPanel sudoku;
        public LoaderPanel(SudokuPanel sudoku){
            this.sudoku = sudoku;           


            // Create an asynchronous callback to handle the result.
            final AsyncCallback callback = new AsyncCallback() {
                public void onSuccess(Object result) {
                    LoaderPanel.this.sudoku.loadGrid((int[][])result);
                }

                public void onFailure(Throwable caught) {
                    new SudokuDialog("Communication failed");
                }
            };
            this.add(new Button("Load Grid", new ClickListener() {
              public void onClick(Widget sender) {
                getService().myMethod("", callback);
              }
            }));
        }
        public static SudokuLoaderServiceAsync getService(){
        // Create the client proxy. Note that although you are creating the
        // service interface proper, you cast the result to the asynchronous
        // version of
        // the interface. The cast is always safe because the generated proxy
        // implements the asynchronous interface automatically.
        SudokuLoaderServiceAsync service = (SudokuLoaderServiceAsync) GWT.create(SudokuLoaderService.class);
        // Specify the URL at which our service implementation is running.
        // Note that the target URL must reside on the same domain and port from
        // which the host page was served.
        //
        ServiceDefTarget endpoint = (ServiceDefTarget) service;
        String moduleRelativeURL = GWT.getModuleBaseURL() + "sudokuloaderservice";
        endpoint.setServiceEntryPoint(moduleRelativeURL);
        return service;
    }
}
